package com.launcher.observer;

import com.launcher.Launch;
import com.launcher.RocketLauncher;

import java.util.List;
import java.util.Observable;

/**
 * @author wouter
 *         Date: 3/25/13
 *         Time: 2:26 PM
 */
public class RocketLaunchChecker extends Observable implements Runnable {
    private int numberOfLaunches = 0;

    @Override
    public void run() {
    	numberOfLaunches = 0;
    	List<Launch> launchesList = null;
        while(numberOfLaunches < RocketLauncher.getAmountToLaunch()) {
//          List<Launch> launchesList = RocketService.getInstance().getLaunches();
        	launchesList = RocketLauncher.getLaunches();

            int size = launchesList.size();
            if(numberOfLaunches != size) 
            {
                setChanged();
                Launch launch = launchesList.get(size - 1);
                notifyObservers("New Launch at: " + launch.getDate().toString() + " with rocket " + launch.getRocket().getParts());
                numberOfLaunches++;
            }


            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        
        RocketLauncher.stopLaunches();
    }
}
